package com.zjq.smartdevice.tasks;

import com.zjq.smartdevice.events.DeviceStausCheckEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @User zhangjiaqi
 * @Project project
 * @Package com.zjq.smartdevice.tasks
 * @Date 2022/3/24 22:24
 */

@EnableScheduling
@Component
public class DeviceStausCheckTask {

    private ApplicationContext context;

    @Autowired
    public void setContext(ApplicationContext context) {
        this.context = context;
    }

    @Scheduled(fixedRate = 45000)
    public void checkStatus(){
        //检查设备的最后一次时间,遍历所有的设备,告诉websocket你该检查设备了
        context.publishEvent(new DeviceStausCheckEvent());
    }
}
